#!/bin/bash
#创建所需目录
base_dir=/opt/microservice2.0/api
rm -rf $base_dir
mkdir -p $base_dir/config
mkdir -p $base_dir/eureka
mkdir -p $base_dir/gateway
mkdir -p $base_dir/goods
mkdir -p $base_dir/member
mkdir -p $base_dir/system
mkdir -p $base_dir/statistics
mkdir -p $base_dir/trade
mkdir -p $base_dir/distribution
mkdir -p $base_dir/consumer

#build the jar
mvn clean install -DskipTests

##将jar copy至相应目录
cp ./config-service/target/config-service-2.0.0.jar $base_dir/config/
cp ./discovery-service/target/eureka-2.0.0.jar $base_dir/eureka/
cp ./gateway-service/target/gateway-service-2.0.0.jar $base_dir/gateway/
cp ./goods-service/target/goods-service-2.0.0.jar $base_dir/goods/
cp ./member-service/target/member-service-2.0.0.jar $base_dir/member/
cp ./system-service/target/system-service-2.0.0.jar $base_dir/system/
cp ./statistics-service/target/statistics-service-2.0.0.jar $base_dir/statistics/
cp ./trade-service/target/trade-service-2.0.0.jar $base_dir/trade/
cp ./distribution-service/target/distribution-service-2.0.0.jar $base_dir/distribution/
cp ./consumer/target/consumer-2.0.0.jar $base_dir/consumer/

#配置文件模板
template=`cat ./template.yml`

#用模板为每个应用生成配置项
printf  "service_name=discovery-service\nservice_port=8000\ncat << EOF\n$template\nEOF" | bash > $base_dir/eureka/bootstrap.yml
printf  "service_name=gateway-service\nservice_port=8001\ncat << EOF\n$template\nEOF" | bash > $base_dir/gateway/bootstrap.yml
printf  "service_name=goods-service\nservice_port=8004\ncat << EOF\n$template\nEOF" | bash > $base_dir/goods/bootstrap.yml
printf  "service_name=member-service\nservice_port=8003\ncat << EOF\n$template\nEOF" | bash > $base_dir/member/bootstrap.yml
printf  "service_name=system-service\nservice_port=8002\ncat << EOF\n$template\nEOF" | bash > $base_dir/system/bootstrap.yml
printf  "service_name=statistics-service\nservice_port=8006\ncat << EOF\n$template\nEOF" | bash > $base_dir/statistics/bootstrap.yml
printf  "service_name=trade-service\nservice_port=8005\ncat << EOF\n$template\nEOF" | bash > $base_dir/trade/bootstrap.yml
printf  "service_name=distribution-service\nservice_port=8008\ncat << EOF\n$template\nEOF" | bash > $base_dir/distribution/bootstrap.yml
printf  "service_name=consumer\nservice_port=8007\ncat << EOF\n$template\nEOF" | bash > $base_dir/consumer/bootstrap.yml
cp ./config-service/src/main/resources/bootstrap.yml $base_dir/config